<template>
  <div>
    <div class="btns">
      <el-button type="primary" v-print="printObj">打印</el-button>
      <el-button class="backBtn" @click="$router.go(-1)">返回</el-button>
    </div>
    <el-col class="docketprint" id="printMe" ref="printContent">
      <admission :list="list"></admission>
    </el-col>
  </div>
</template>

<script>
import admission from "./componments/admission.vue";
import {
  addAdmissionCard,
  admissionCardList,
} from "@/api/testManagement/examAttendanceDocket.js";
export default {
  components: {
    admission,
  },
  data() {
    return {
      printObj: {
        id: "printMe", //打印区域 Dom ID
        popTitle: "",
        extraCss: "https://www.google.com,https://www.google.com",
        extraHead:
          '<meta http-equiv="Content-Language"content="zh-cn"/>,<style> #printMe { height: auto !important; } <style>', //  可以传进去  style tag 标签；注意要逗号分隔   解决特定区域不显示问题；
      },
      list: [],
    };
  },
  created() {
    this.addAdmissionList();
  },
  methods: {
    async addAdmissionList() {
      try {
        await addAdmissionCard({ examId: this.$route.params.id });
        const res = await admissionCardList({
          examId: this.$route.params.id,
          pageSize: 10000,
        });
        if (res.code == 200) {
          if (res.rows.length != 0) {
            console.log(res);
            this.list = res.rows;
            this.list.forEach((item) => {
              item.paperInformation = JSON.parse(item.paperInformation);
            });
            this.list.forEach((item) => {
              return item.paperInformation.forEach((it) => {
                console.log(it.subjectTime.split(" "));
                return (it.subjectTime = it.subjectTime.split(" "));
              });
            });
            this.list.forEach(item => {
              return item.paperInformation.forEach(it => {
                return it.subjectTime[1] = it.subjectTime[1].split('至')
              })
            })
          } else {
            this.$message.error("暂无数据");
          }
        } else {
          this.$message.error("数据获取失败");
        }
      } catch (error) {
        console.log(error);
      }
    },
  },
};
</script>

<style scoped>
.btns {
  margin-bottom: 10px;
  text-align: center;
}
.backBtn {
  margin-left: 100px;
}
</style>
<style media="print">
@page {
  size: auto; /* auto is the initial value */
  margin: 8mm; /* this affects the margin in the printer settings */
}
</style>


